﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpAlgorithm
{
    class Fliptile
    {
        public Fliptile()
        {
            int testCount = Int32.Parse(TestConsole.ReadLine());

            for (int testCase = 1; testCase <= testCount; testCase++)
            {
                string[] input = TestConsole.ReadLine().Split(' ');
                int m = Int32.Parse(input[0]);
                int n = Int32.Parse(input[1]);
                int[] matrix = new int[n + 1];
                for (int i = 1; i <= n; i++)
                {
                    string line = TestConsole.ReadLine().Replace(" ", "").Trim();
                    matrix[i] = Convert.ToInt32(line, 2);
                }
                
                for (int i = 0; i < (int)Math.Pow(2, m); i++)
                {
                    int[] result = new int[n + 1];
                    for (int j = 1; j <= n; j++)
                    {
                        result[j] = matrix[j];
                    }
                    int[] flip = new int[n + 1];
                    flip[1] = i; 
                    for (int j = 2; j <= n; j++)
                    {
                        flip[j] = result[j - 1];
                        result[j - 1] ^= flip[j];
                        result[j] = SameLine(result[j], flip[j], m);
                        if (j < n)
                        {
                            result[j + 1] ^= flip[j];
                        }
                    }
                    if (result[n] == 0)
                    {
                        break;
                    }
                }
                Console.WriteLine(string.Format("Case #{0}: {1}", testCase, "result"));
            }
        }

        
        private int SameLine(int matrix, int flip, int m)
        {
            int rl = 0;
            int p = (int)Math.Pow(2, 4) - 1;
            for (int i = 0; i < m; i++)
            {
                if ((1 << i & flip) > 0) //각 자리수 값이 1일 경우
                {
                    rl ^= (7 << i >> 1 & p); //눌러진 값의 양쪽 값을 1로 변환
                }
            }
            return matrix ^ rl ^ flip;
        }
    }
}
